﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using yncTech.BusinessObjects;
using yncTech.Common;

public partial class Admin_FinSav_FinSav002a : AdminBasePage
{
    decimal[] ids;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["ids"] != null)
        {
            ids = Request.QueryString["ids"].TrimEnd(',').Split(',').Select(r=>decimal.Parse(r)).ToArray();
        }
        if (!IsPostBack)
        {
            txtInDate.Value = DateTime.Now.ToString(ConstantValue.DateFormat);
            txtVoucherDate.Value = DateTime.Now.ToString(ConstantValue.DateFormat);

            btnSave.Text = "修改";
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            lbMessage.Text = "";


            FinReceiptCollection receipts = new FinReceiptCollection();

            receipts.Query.Where(receipts.Query.ReceiptID.In(ids));

            receipts.Query.Load();


            foreach (var receipt in receipts)
            {
              
                receipt.DocumentsType = drpDocType.SelectedValue;
                receipt.IsConfirmed = false;


                receipt.Division = drpDivision.SelectedValue;
                receipt.VoucherDescription = drpDocDesc.SelectedValue;
                receipt.VoucherDate = txtVoucherDate.Value;
                receipt.FirstStorageDate = txtInDate.Value.ToDate();
                receipt.CompanyCode = drpCompany.SelectedValue;

                receipt.StorageLocation = decimal.Parse(drpLocation.SelectedValue);
                receipt.StorageStatus = drpStorageStatus.SelectedValue;
                receipt.FunctionDept = drpFunctionDept.SelectedValue;
                receipt.Comments = txtComments.Text;
                receipt.UpdatedBy = LoginUserInfo.CurrentUser.LoginName;
                receipt.UpdatedDttm = DateTime.Now;
                receipt.TransactionID = Guid.NewGuid().ToString();
                receipt.VersionNo = receipt.VersionNo + 1;
            }

            receipts.Save();

            WebHelper.CloseDialog(true);
        }
        catch (Exception ex)
        {
            lbMessage.Text = ex.Message;
        }

    }
}